using BuildingBlocks.Core.Entities;
using Identity.Domain.Exceptions;
using Identity.Domain.ValueObjects;

namespace Identity.Domain.Aggregates;

public class Permission : AggregateRoot<Guid>
{
    public string Key { get; private set; }
    public string Name { get; private set; }
    public string? Description { get; private set; }



    private Permission() { }

    public static Permission Create(string key, string name, string? description)
    {
        if (string.IsNullOrWhiteSpace(name)) throw new DomainException("name not null");

        return new Permission()
        {
            Id = Guid.NewGuid(),
            Key = key,
            Name = name,
            Description = description,

        };
    }

    public void ChangeName(string newName)
    {
        if (newName == Name) return;
        if (string.IsNullOrWhiteSpace(newName)) throw new DomainException("name not null");

        Name = newName;
    }
    public void ChangeKey(string newKey)
    {
        if (newKey == Key) return;
        if (string.IsNullOrWhiteSpace(newKey)) throw new DomainException("key not null");

        Key = newKey;
    }
    public void ChangeDescription(string? newDescription)
    {
        if (Description == newDescription) return;
        Description = newDescription;
    }


}